/**
 * 功能:显示我的微博主页
 * 创建日期: 2012-03-16
 * 创建人: 全轩
 * 功能修正说明:
 * 		
 */
if(!this.StatusWin)
{
	this.StatusWin = {};
}

(function(){

	if(!StatusWin.win)
	{
		StatusWin.win = Ti.UI.createWindow({
		title:'我的首页',
		});
	}
	
	if(!StatusWin.rows)
	{
		StatusWin.rows = [];
	}
	if(!StatusWin.firstrweetid)
	{
		StatusWin.firstrweetid = 0
	}
	
	if(!StatusWin.tableview){
		StatusWin.tableview = Ti.UI.createTableView({minRowHeight:60, top:0,height:460-86,zIndex:999});
	 	
	 	Util.HeaderPullView(StatusWin.tableview,
									function(timeline, addType)
									{
										StatusWin.List(timeline, addType);
									}
								);
		
	}
	
	if(typeof StatusWin.CreateRowHeader !== 'function')
	{
		StatusWin.CreateRowHeader = function(tweet)
		{
				//*昵称、发表时间
				var topView = Ti.UI.createView({
					height : 20,
					left:0,
					top:0,
					backgroundColor:'#97a4ad',
				});
				//用户昵称
				var screen_name = Ti.UI.createLabel({
					text : tweet.user.screen_name,
					width : 200,
					height : 'auto',
					color : '#369',
					font : {fontWeight: 'bold', fontSize : 14},
					left:0,
					top:0,
					
				});				
				topView.add(screen_name);
				
				//评论
				var btnreplay = Ti.UI.createButton({
					backgroundImage:'images/header/pl_icon.png',
					width:12,
					height:14,
					left:150,
				});
				topView.add(btnreplay);
				
				//转发
				var btnretweet = Ti.UI.createButton({
					backgroundImage:'images/header/zf_icon.png',
					width:14,
					height:12,
					right:100,
				});
				topView.add(btnretweet);
				
				//发表时间
				var created_at = Ti.UI.createLabel({
					text : tweet.created_at,
					width : 150,
					height : 'auto',
					color : '#369',
					font : {fontSize:10},
					right:0,
					top : 3,					
					textAlign : 'right'
				});
				topView.add(created_at);
				
				return topView;
		}
	}
	
	if(typeof StatusWin.CreateIndex !== 'function')
	{
		StatusWin.CreateIndex = function(datarows)
		{
			var index = [
							{title:'A',index:0},
							{title:'B',index:5},
							{title:'C',index:9},
							{title:'D',index:13},
							{title:'E',index:19},
							{title:'F',index:23},
							{title:'G',index:27},
							{title:'H',index:30},
							{title:'I',index:33},
							{title:'J',index:36},
							{title:'K',index:41},
							{title:'L',index:44},
							{title:'M',index:48},
							{title:'N',index:52},
							{title:'O',index:55},
							{title:'P',index:60}
						];
			return index;
		}
	}
	
	
	//显示我的微博首页的列表信息
	if(typeof StatusWin.List !== 'function')
	{
		StatusWin.List = function(timeline,addType)
		{	
			var data = [];
			var dataSection = [];
			
			for(var i=0; i < timeline.length; i++) {								
				var tweet = timeline[i];
				
				var rowSection = Ti.UI.createTableViewSection({
					height:'auto',		
					headerView:	StatusWin.CreateRowHeader(tweet),
					id: tweet.id,								
				});	
				
				var row = Ti.UI.createTableViewRow({
					height:'auto',											
				});	
				
				var tweetView = Ti.UI.createView({
					height: 'auto',
					layout:'vertical',
					left:70,
					top:10,
					bottom:10,
					right:10,
					id:tweet.id					
				});			
				
				//微博正文
				var tweetTxt = Ti.UI.createLabel({
					text : tweet.text,
					height : 'auto',
					top : 0,
					left : 0,
					font : {fontSize:14},
					color : '#222',
					id:	tweet.id		
				});
				tweetView.add(tweetTxt);								
				
				//来源
				var sourceTxt = Ti.UI.createLabel({
					text : '来自:'+tweet.source,
					height : 'auto',
					top : 5,
					left : 0,
					font : {fontSize : 12},
					color : '#666'
				});
				tweetView.add(sourceTxt);				
																
				row.add(tweetView);
				
				var imageView = Ti.UI.createImageView({
					image: tweet.user.profile_image_url,
					left:10,
					top:6,
					height:48,
					width:48,
					title:tweet.user.id
				});
				
				imageView.addEventListener('click', function(e){
					ProfileHandler.ShowInfo(this.title,StatusWin.win);
				});
				row.add(imageView);				
												
				tweetView.addEventListener('click', function(e) {																			
					//ta.control.tweet.view(this.id,ta.ui.tweetList.win);					
				});
			
				
				rowSection.add(row);
				rowSection.setHeight(20+tweetView.height);
				dataSection.push(rowSection);
			}	
			
			
			if(addType == 1) 
			{
				var rows = StatusWin.tableview.data;
				//Ti.API.info(dataSection.length);
				//Ti.API.info(rows.length);
				rows = rows.concat(dataSection);
				//Ti.API.info(rows.length);
				StatusWin.tableview.setData(rows);
			} 
			else if(addType == 2) 
			{
				StatusWin.tableview.insertRowBefore(dataSection);
			} 
			else 
			{
				StatusWin.rows = dataSection;
				StatusWin.tableview.setData(dataSection);
			}
			StatusWin.tableview.index = StatusWin.CreateIndex(data);
			//
		}
	}
	
	//我的微博首页初始化
	if(typeof StatusWin.Init !== 'function')
	{
		StatusWin.Init = function(parentWin)
		{
			StatusWin.parentwin = parentWin;
			StatusesInfo.GetData(20,function(data){
				StatusWin.List(data,'0');
				
				StatusWin.win.setTitleControl(Util.CreateTweetListTitleControl());
				StatusWin.win.add(StatusWin.tableview);
			});
		}
	}
}())

//SinaApp.StatusWin = StatusWin;
